<template>
  <div class="advert">
     <div class="content">
       <div class="content_top">
         <h2>平台广告显示</h2>
         <i-switch :disabled="!is_edit" true-color="#13ce66" false-color="#ff4949" v-model="adswitch" @on-change="change" />
         <span>{{adswitch?'显示':'不显示'}}</span>
       </div>
       <div style="text-align: center;margin-top:20px">
            <Button type="primary" @click="handleSubmit('formInline')">完成</Button>
       </div>
     </div>
  </div>
</template>
<script>
import uploadImg from '@/components/uploadImg'
export default {
   data() {
    return {
      is_edit:true,
      formStyle:{
        width:'290px',
        height:'100px',
        lineHeight:'100px'
      },
      Bswitch:false,
      adswitch:false,
      is_ad:0,
      top_ad_img  :'',
      top_ad_url :'',
      bottom_ad_img :'',
      bottom_ad_url  :'',
      sign_top_ad_img  :'',
      sign_top_ad_url :'',
      sign_bottom_ad_img :'',
      sign_bottom_ad_url  :'',
      vip_top_ad_img  :'',
      vip_top_ad_url :'',
      vip_bottom_ad_img :'',
      vip_bottom_ad_url  :'',
    }
  },
  mounted() {
    this.getDatas();
  },
  methods: {
    handleSuccess(value) {
      console.log(value)
      this.top_ad_img =  value  // 上传图片的路径名
    },
    handlebottomSuccess(value) {
      console.log(value)
      this.bottom_ad_img =  value  // 上传图片的路径名
    },
    handleSuccess1(value) {
      console.log(value)
      this.sign_top_ad_img =  value  // 上传图片的路径名
    },
    handlebottomSuccess1(value) {
      console.log(value)
      this.sign_bottom_ad_img =  value  // 上传图片的路径名
    },
    handleSuccess2(value) {
      console.log(value)
      this.vip_top_ad_img =  value  // 上传图片的路径名
    },
    handlebottomSuccess2(value) {
      console.log(value)
      this.vip_bottom_ad_img =  value  // 上传图片的路径名
    },
    change (status) {
        this.handleSubmit()
    },
    getDatas(){
      let params = {
         
      }
      this.$api.getseverdetail(params)
          .then(res => {
            console.log(res);
            if (res.code == 200) {
               this.is_ad = res.data.is_ad
               this.adswitch = res.data.is_ad == 1 ? false:true
               this.top_ad_img = res.data.top_ad_img
               this.top_ad_url = res.data.top_ad_url
               this.bottom_ad_img = res.data.bottom_ad_img
               this.bottom_ad_url = res.data.bottom_ad_url
               this.sign_top_ad_img = res.data.sign_top_ad_img
               this.sign_top_ad_url = res.data.sign_top_ad_url
               this.sign_bottom_ad_img = res.data.sign_bottom_ad_img
               this.sign_bottom_ad_url = res.data.sign_bottom_ad_url
               this.vip_top_ad_img = res.data.vip_top_ad_img
               this.vip_top_ad_url = res.data.vip_top_ad_url
               this.vip_bottom_ad_img = res.data.vip_bottom_ad_img
               this.vip_bottom_ad_url = res.data.vip_bottom_ad_url
          }
      })
    },
    handleSubmit(value){
        let params = {
          is_ad:this.adswitch?2:1,
          top_ad_img:this.top_ad_img ,
          top_ad_url:this.top_ad_url ,
          bottom_ad_img:this.bottom_ad_img, 
          bottom_ad_url:this.bottom_ad_url, 
          sign_top_ad_img:this.sign_top_ad_img ,
          sign_top_ad_url:this.sign_top_ad_url ,
          sign_bottom_ad_img:this.sign_bottom_ad_img, 
          sign_bottom_ad_url:this.sign_bottom_ad_url, 
          vip_top_ad_img:this.vip_top_ad_img ,
          vip_top_ad_url:this.vip_top_ad_url ,
          vip_bottom_ad_img:this.vip_bottom_ad_img, 
          vip_bottom_ad_url:this.vip_bottom_ad_url, 
        };
        this.$api.editsever(params)
          .then(res => {
            console.log(res);
            if (res.code == 200) {
              this.$Message.success('设置成功');
              this.getDatas();
            }
        })    
    },
  },
  components: {
    uploadImg
  } 
}
</script>
<style lang="less" scoped>
    @import './index.less';
</style>
